<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../../config.inc.php");
session_start();
$_LangPath = "changewagerList";
include_once(__Admin_Path."/logincheck_op.php");
include_once(__Language_Path."/selectlanguage_admin.php");
include_once(__Modules_Path."/BetType.lib.php");
include_once(__Modules_Path."/Lotto.lib.php");
include_once(__Modules_Path."/Gamble.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once(__Common_Path."/SysParam.inc.php");
include_once(__Common_Path."/Lotto.inc.php");

$arrPower = CheckUsePower("changewagerlist");
if($arrPower === false)ErrMsgOutputHTML("Error", "", 1);


$strSQL = "";
$arrBID = array();
$arrBet = array();
$arrParlay = array();
if($_data["BID"] != "")$arrBID = split(",", $_data["BID"]);

$intMemID = (int)$_data["MemID"];
$intSubID = (int)$_data["SubID"];
$intMainID = (int)$_data["MainID"];
$intLottoID = (int)$_data["LottoID"];
$intBT = (int)$_data["Bet_Type"];
$intOID = (int)$_data["OddsID"];
$intGID = (int)$_data["GambleID"];
$intNumber = (int)$_data["Number"];
$intWagerType = (int)$_data["WagerType"];
$intWagerStatus = (int)$_data["WagerStatus"];
$intShowlist = (int)$_data["Showlist"];

$strSQL = "";
if(!empty($intMemID))$strSQL .= " and a.MemID = '".$intMemID."'";
if(!empty($intSubID))$strSQL .= " and a.SubID = '".$intSubID."'";
if(!empty($intMainID))$strSQL .= " and a.MainID = '".$intMainID."'";
if(!empty($intLottoID))$strSQL .= " and a.LottoID = '".$intLottoID."'";
if(!empty($intBT))$strSQL .= " and a.Bet_Type = '".$intBT."'";
if(!empty($strPayupDate0) && !empty($strPayupDate1))$strSQL .= " and (a.PayupDate between '".$strPayupDate0."' and '".$strPayupDate1."')";
if(!empty($intOID))$strSQL .= " and a.OddsID = '".$intOID."'";
if(!empty($intGID))$strSQL .= " and a.GambleID = '".$intGID."'";
if(!empty($intNumber))$strSQL .= " and a.Number = '".$intNumber."'";
if(!empty($_data["WagerType"]))$strSQL .= " and a.WagerType = '".$intWagerType."'";
if(!empty($_data["WagerStatus"]))$strSQL .= " and a.isPayOff = '".$intWagerStatus."'";

if(sizeof($arrBID) > 0)$strSQL .= " and a.ID in (".join(",", $arrBID).")";

if($arrPower[1] == "no"){
	$arrGame = getMoreGambleData("", "", "0", 0, "");
	if($arrGame === false){
		$GLOBALS["errormessage"] = "Find Gamble Data Error!!";
		$GLOBALS["errorhidden"] = "\n Error: ".PMA_mysql_error($_ConnMaster).",\nSQL: ".$strSQL.",\nLine: ".__LINE__.",\nPage: ".__FILE__;
		ErrMsgOutputHTML("Error", "", 1);
	}
}

if($strSQL != ""){
	if($arrPower[1] != "all"){
		$strSQL .= " and a.WagerType = '1'";
		$strSQL .= " and a.isPayOff > -2 ";
	}
	$strSQL = "select a.ID, a.LottoID, a.GambleID, b.BetDate, b.BetTime, a.Bet_Type, b.Content, a.MemID, a.MemStake, a.MemResult, a.isPayOff, b.MemAccount, b.OneStake from `bet_BetList` a, `bet_BetListContent` b where a.ID > 0 and a.ID = b.ID ".$strSQL." order by a.ID";
}
//print "<!--".$strSQL."//-->";

//print $data["rop"];
$intTolStake = 0;
$intTolResult = 0;
if($strSQL != "" && $intShowlist != 1){
	//print $strSQL;
	if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
		$GLOBALS["errormessage"] = "Find Wager Data Error!";
		$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".PMA_mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
		ErrMsgOutputHTML("Error", "", 1);
	}
	$arrBID = array();
	$arrBet = array();
	$arrMemID = array();
	$arrMemSccount = array();
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrBet[$Rows -> ID]["BetDate"] = DateForm($Rows -> BetDate, $Rows -> BetTime, "Y-m-d");
		$arrBet[$Rows -> ID]["BetTime"] = TimeForm($Rows -> BetDate, $Rows -> BetTime, "H:i:s");
		$arrBet[$Rows -> ID]["Bet_Type"] = $Rows -> Bet_Type;
		$arrBet[$Rows -> ID]["ScoreID"] = $Rows -> ScoreID;
		$arrBet[$Rows -> ID]["Score"] = $Rows -> Score;
		$arrBet[$Rows -> ID]["GambleID"] = $Rows -> GambleID;
		$arrBet[$Rows -> ID]["Content"] = $Rows -> Content;
		$arrBet[$Rows -> ID]["MemID"] = $Rows -> MemID;
		$arrBet[$Rows -> ID]["MemStake"] = $Rows -> MemStake;
		$arrBet[$Rows -> ID]["OneStake"] = $Rows -> OneStake;
		$arrBet[$Rows -> ID]["MemResult"] = $Rows -> MemResult;
		$arrBet[$Rows -> ID]["isPayOff"] = $Rows -> isPayOff;
		$arrBet[$Rows -> ID]["MemAccount"] = $Rows -> MemAccount;
		$arrBet[$Rows -> ID]["LottoID"] = $Rows -> LottoID;
		//$arrMemID[] = $Rows -> MemID;
		$arrBID[] = $Rows -> ID;
		if($Rows -> isPayOff >= 0){
			$intTolStake += $Rows -> MemStake;
			$intTolResult += $Rows -> MemResult;
		}
	}

	//找出所有會員帳號
	/*if(sizeof($arrMemID) > 0){
		$strSQL = "select ID, Account from bet_Member where ID in (".join(",", $arrMemID).")";
		if(!$RS = @mysql_query($strSQL)){
			$GLOBALS["errorhidden"] = "Find User Data Error!";
			$GLOBALS["errorhidden"] = "SQL: ".$strSQL.", \nError: ".mysql_error($$_Conn).", \nLine: ".__LINE__.", \nPage: ".__FILE__;
			ErrMsgOutputHTML("Error", "", 1);
		}
		while($Rows = mysql_fetch_object($RS)){
			$arrMemAccount[$Rows -> ID] = $Rows -> Account;
		}
	}*/
}

if($intLottoID == 0)$intLottoID = (empty($_MemInitLottoID))?1:$_MemInitLottoID;
$intLType = $_arrLotto[$intLottoID]["LType"];
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="/css/backend.css" type="text/css">
<script language="JavaScript1.2" type="text/javascript" src="/inc/admin_envirset.js"></script>
<script language="JavaScript">
<!--
	var strRowClassName = ",datarow,";
	function SelectAllBet(isOff){
		with(document.beMemberFrm){
			if(arrBID.length){
				for(var i = 0; i < arrBID.length; i++)arrBID[i].checked = true;
			}else{
				arrBID.checked = true;
			}
		}
	}

	function arrAccept(isAccept){
		var arrBIDs = new Array(), j = 0, arrParlays = new Array();
		with(document.beMemberFrm){
			if(arrBID.length > 0){
				for(var i = 0; i < arrBID.length; i++){
					if(arrBID[i].checked){
						arrBIDs[j] = arrBID[i].value;
						j++
					}
				}
			}else{
				if(arrBID.checked){
					arrBIDs[j] = arrBID.value;
					j++
				}
			}

			if(document.getElementById("Parlay")){
				if(Parlay.length > 0){
					for(var i = 0; i < Parlay.length; i++){
						if(Parlay[i].checked){
							arrParlays[j] = Parlay[i].value;
							j++
						}
					}
				}else{
					if(document.getElementById("Parlay").checked){
						arrParlays[j] = Parlay.value;
						j++
					}
				}
			}
		}
		document.AcceptForm.isAccept.value = isAccept;

		var strAcceptWager = "<?php print $_strChangeWagerList["AcceptWager"];?>";
		var strNotAcceptWager = "<?php print $_strChangeWagerList["NotAcceptWager"];?>";
		if(arrBIDs.length > 0 || arrParlays.length > 0){
			if(arrBIDs.length > 0)document.AcceptForm.BID.value = arrBIDs.join(",");
			if(arrParlays.length > 0)document.AcceptForm.arrParlay.value = arrParlays.join(",");
			if(confirm((isAccept == 0)?strAcceptWager:strNotAcceptWager)){
				document.AcceptForm.submit();
			}
		}
	}

	/*function ImportPassword(){
		strItem = prompt("Plass input your password!!!", "");
		document.AcceptForm.ChangePWD.value = strItem;
	}*/

	function ShowLog(WagerID){
		window.open("ShowLog.php?WagerID="+WagerID,"ShowLogWindow","toolbar=no,width=540,height=400,top=0,left=0,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
	}
//-->
</script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #F7F7F7;
	font-size: 12px
}
.BetID{
	color: #FF0000;
	font-weight: 700;
}
//-->
</style>
</head>
<body>
<form action="<?php print $_SERVER["PHP_SELF"];?>" method="Post" name="beMemberFrm">
<input type="hidden" name="op" value="ChangeRiskBet">
<input type="hidden" name="Showlist" value="0">
<table class=content_b>
<tr>
<td valign="center" style="font-weight: 700; font-size: 16px"><?php print $_strChangeWagerList["Title"]?></td>
<td valign="top" align="right">&nbsp;</td></tr>
<tr>
<td valign="top" colspan="2">
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#0054E3F"><tr><td>
<table width="800" border="0" cellpadding="3" cellspacing="1" style="font-size: 12px">
<tr bgcolor="#7A96E9" align="center">
<td width="40"><?php print $_strChangeWagerList["Select"];?></td>
<td width="120"><?php print $_strChangeWagerList["TimeTicketNo"];?></td>
<td width="80"><?php print $_strChangeWagerList["Member"];?></td>
<td width="70"><?php print $_strChangeWagerList["Type"];?></td>
<td width="220"><?php print $_strChangeWagerList["Content"];?></td>
<td width="80"><?php print $_strChangeWagerList["Stake"];?></td>
<td width="80"><?php print $_strChangeWagerList["Result"];?></td>
<td width="50"><?php print $_strChangeWagerList["Status"];?></td>
<td width="50"><?php print $_strChangeWagerList["Log"];?></td>
</tr>
<?php
while(list($k, $v) = each($arrBet)){
	$BetNo = abs($v["isPayOff"]);
?>
<tr class="datarow" bgcolor="#FFFFFF"><label for="isArray<?php print $k;?>">
<td align="center">
<?php 
	if(preg_match("/all|supple/", $arrPower[1]) || $v["MemAccount"] != $_KSysParam[SuppleReAccount]){
		if($arrPower[1] == "no"){
			if($arrGame[$v["GambleID"]]["ID"] > 0)print '<input type="checkbox" name="arrBID" value="'. $k.'" id="isArray'. $k.'">';
		}else{
			print '<input type="checkbox" name="arrBID" value="'. $k.'" id="isArray'. $k.'">';
		}
	} 
?></td>
<td align="left"><?php print $v["BetDate"];?>&nbsp;&nbsp;<?php print $v["BetTime"];?><br /><a class="BetID"><?php print $k;?></a></td>
<td align="left"><?php print $v["MemAccount"];?></td>
<td align="right"><?php print $_arrBet_Type[$_arrLotto[$v["LottoID"]]["LType"]][$v["Bet_Type"]];?></td>
<td align="left"><?php print WagerFormTrans($v["LottoID"], $v["Bet_Type"], $v["Content"]);?></td>
<td align="right"><?php
	if($v["Bet_Type"] >= 7 && $v["Bet_Type"] <= 11 && !empty($v["OneStake"])){
		if($v["MemStake"] / $v["OneStake"] > 1)print (string)$v["OneStake"]." x ".(string)round($v["MemStake"] / $v["OneStake"])."<br /><br />";
	}
	print $v["MemStake"];
?></td>
<td align="right"><?php print $v["MemResult"];?></td>
<td align="center"><?php
	switch($v["isPayOff"]){
		case -2:
			print "<b style=\"color:#FF0000\">Not Deal</b>";
			break;
		case -1:
			print "<b style=\"color:#FF0000\">".$_strChangeWagerList["NotAccept"]."</b>";
			break;
		default:
			print $_strChangeWagerList["Accept"];
			break;
	}
?></td>
<td align="center"><a href="JavaScript:ShowLog('<?php print $k;?>')"><?php print $_strChangeWagerList["Log"];?></a></td>
</label></tr>
<?php
}  //while(list($k, $v) = each($arrBet))//
?>
<tr bgcolor="#FFFFFF" align="right">
<td colspan="5"><?php print $_strChangeWagerList["Total"];?></td>
<td><?php print $intTolStake;?></td>
<td><?php print $intTolResult;?></td>
<td><?php print @sizeof($arrBet);?></td>
<td>&nbsp;</td>
</tr>
</table>
</td></tr>
</table>
</td>
</tr>
</table>
<input type="button" value="<?php print $_strChangeWagerList["SelectAll"];//全部選取?>" onclick="SelectAllBet(0)" class="submit">
<input type="reset" value="<?php print $_strChangeWagerList["SelectNo"];//全部取消?>" class="submit">
</td>
</tr>
</table><br /><br />
<fieldset style="width: 450px">
	<legend>Search</legend>
	<table style="width: 400px; font-size: 12px">
	<tr>
		<td align="right"><?php print $_strChangeWagerList["WagerID"];?></td>
		<td align="left"><input type="text" name="BID" value="<?php print $_data["BID"];?>" size="50" class="input_text"></td>
	</tr><tr>
		<td align="right"><?php print $_strChangeWagerList["Lotto"];?></td>
		<td align="left"><?php print MakeLottoSelect($_arrLotto, $intLottoID, "LottoID", "document.beMemberFrm.Showlist.value=1;document.beMemberFrm.submit();", $_intLang);?></td>
	</tr><tr>
		<td align="right"><?php print $_strChangeWagerList["SerialNo"];?></td>
		<td align="left"><?php print MakeGambleNoSelect($intLottoID, $_data["GambleID"], "GambleID", "", 4, $_arrLotto);?></td>
	</tr><tr>
		<td align="right"><?php print $_strChangeWagerList["Type"];?></td>
		<td align="left"><?php print SelectBetType($_data["Bet_Type"], "Bet_Type", "", $intLType);?></td>
	</tr>
<?php if($arrPower[1] == "all"){ ?>
	<tr>
		<td align="right"><?php print $_strChangeWagerList["WagerType"];?></td>
		<td align="left">
			<select name="WagerType">
				<option value="">--select--</option>
				<option value="0"<?php print ($_data["WagerType"] == "0")?" selected":"";?>><?php print $_strChangeWagerList["Common"];?></option>
				<option value="1"<?php print ($_data["WagerType"] == "1")?" selected":"";?>><?php print $_strChangeWagerList["Supple"];?></option>
			</select>
		</td>
	</tr>
<?php } ?>
	<tr>
		<td align="right"><?php print $_strChangeWagerList["WagerStatus"];?></td>
		<td align="left">
			<select name="WagerStatus">
				<option value="">--select--</option>
				<option value="0"<?php print ($_data["WagerStatus"] == "0")?" selected":"";?>><?php print $_strChangeWagerList["Accept"];?></option>
				<option value="-1"<?php print ($_data["WagerStatus"] == "-1")?" selected":"";?>><?php print $_strChangeWagerList["NotAccept"];?></option>
				<?php if($arrPower[1] == "all"){ ?>
				<option value="-2"<?php print ($_data["WagerStatus"] == "-2")?" selected":"";?>>Not Deal</option>
				<?php } //if($arrPower[1] == "all")?>
			</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="Go" class="submit">
		</td>
	</tr>
	</table>
</fieldset>
</form>

<?php //if($arrPower[1] == "all" || $arrPower[1] == "supple"){ ?>
<fieldset style="width: 450px">
	<legend>Password&nbsp;(<?php print date("Y-m-d");?>)</legend>
		<form method="Post" action="UpdateWagerList.php" name="AcceptForm" target="_self">
			<!--<input type="Password" name="ChangePWD" value="" size="50" class="input_text">//-->
			<input type="button" value="<?php print $_strChangeWagerList["Accept"];?>" onclick="arrAccept(0)" class="submit">
			<input type="button" value="<?php print $_strChangeWagerList["NotAccept"];?>" onclick="arrAccept(-1)" class="submit">
			<?php if($arrPower[1] == "all"){ ?><input type="button" value="Not Deal" onclick="arrAccept(-2)" class="submit"><?php } //if($arrPower[1] == "all")?>
			<input type="hidden" name="op" value="UpdateRiskBet">
			<input type="hidden" name="rop" value="ChangeRiskBet">
			<input type="hidden" name="isAccept" value="0">
			<input type="hidden" name="BID" value="">
			<input type="hidden" name="arrBID" value="<?php print join(",", $arrBID);?>">
			<input type="hidden" name="arrParlay" value="">
		</form>
</fieldset>
<?php //} ?>
</body>
</html>
<?php @mysql_close($$_Conn); ?>